home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Dialog Boxes / AboutBox / AboutBox.cs next >
Encoding:
Text File  |  2001-01-15  |  3.1 KB  |  89 lines

  1. //---------------------------------------
  2. // AboutBox.cs ⌐ 2001 by Charles Petzold
  3. //---------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class AboutBox: Form
  9. {
  10.      public static void Main()
  11.      {
  12.           Application.Run(new AboutBox());
  13.      }
  14.      public AboutBox()
  15.      {
  16.           Text = "About Box";
  17.           Icon = new Icon(GetType(), "AboutBox.AforAbout.ico");
  18.  
  19.           Menu = new MainMenu();
  20.           Menu.MenuItems.Add("&Help");
  21.           Menu.MenuItems[0].MenuItems.Add("&About AboutBox...",
  22.                                         new EventHandler(MenuAboutOnClick));
  23.      }
  24.      void MenuAboutOnClick(object obj, EventArgs ea)
  25.      {
  26.           AboutDialogBox dlg = new AboutDialogBox();
  27.           dlg.ShowDialog();
  28.      }
  29. }
  30. class AboutDialogBox: Form
  31. {
  32.      public AboutDialogBox()
  33.      {
  34.           Text = "About AboutBox";
  35.  
  36.           StartPosition   = FormStartPosition.CenterParent;
  37.           FormBorderStyle = FormBorderStyle.FixedDialog;
  38.           ControlBox      = false;
  39.           MaximizeBox     = false;
  40.           MinimizeBox     = false;
  41.           ShowInTaskbar   = false;
  42.  
  43.           Label label1     = new Label();
  44.           label1.Parent    = this;
  45.           label1.Text      = " AboutBox Version 1.0 ";
  46.           label1.Font      = new Font(FontFamily.GenericSerif, 24, 
  47.                                       FontStyle.Italic);
  48.           label1.AutoSize  = true;
  49.           label1.TextAlign = ContentAlignment.MiddleCenter;
  50.  
  51.           Icon icon = new Icon(GetType(), "AboutBox.AforAbout.ico");
  52.  
  53.           PictureBox picbox = new PictureBox();
  54.           picbox.Parent     = this;
  55.           picbox.Image      = icon.ToBitmap();
  56.           picbox.SizeMode   = PictureBoxSizeMode.AutoSize;
  57.           picbox.Location   = new Point(label1.Font.Height / 2, 
  58.                                         label1.Font.Height / 2);
  59.  
  60.           label1.Location  = new Point(picbox.Right,label1.Font.Height / 2);
  61.  
  62.           int iClientWidth = label1.Right;
  63.  
  64.           Label label2     = new Label();
  65.           label2.Parent    = this;
  66.           label2.Text      = "\x00A9 2001 by Charles Petzold";
  67.           label2.Font      = new Font(FontFamily.GenericSerif, 16);
  68.           label2.Location  = new Point(0, label1.Bottom + 
  69.                                           label2.Font.Height);
  70.           label2.Size      = new Size(iClientWidth, label2.Font.Height);
  71.           label2.TextAlign = ContentAlignment.MiddleCenter;
  72.  
  73.           Button button   = new Button();
  74.           button.Parent   = this;
  75.           button.Text     = "OK";
  76.           button.Size     = new Size(4 * button.Font.Height, 
  77.                                      2 * button.Font.Height);
  78.           button.Location = new Point((iClientWidth - button.Size.Width) / 2,
  79.                                    label2.Bottom + 2 * button.Font.Height);
  80.  
  81.           button.DialogResult = DialogResult.OK;
  82.  
  83.           CancelButton = button;
  84.           AcceptButton = button;
  85.  
  86.           ClientSize = new Size(iClientWidth, 
  87.                                 button.Bottom + 2 * button.Font.Height);
  88.      }
  89. }